package com.woniuxy.meal.util;


import cn.hutool.core.io.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;

@Component
public class UploadFileUtil {

    @Autowired
    private OSSUtil ossUtil;

    public String uploadImg(MultipartFile file) throws IOException {
        InputStream is = file.getInputStream();
        String originalFilename = file.getOriginalFilename();
        String suffix = FileUtil.getSuffix(originalFilename);
        String fileName = UUID.randomUUID().toString().replaceAll("-", "");
        return ossUtil.uploadFile(is, fileName + "." + suffix, "bucket-book-fjx");
    }

}
